/*
*optimizationSelect.js
*配置模拟 下拉选择组件集合
*/

import React,{Component}  from 'react'
import {message,Select,Row,InputNumber } from 'antd';


const Option = Select.Option;

//优化模型
const OptimizeModelSelect=({data,value,dispatch,tag})=>{
	console.log('OptimizeModelSelect>>',data,value)
	const myProps={
		defaultValue:'均值方差模型',
		data,
		onChange:(v)=> {
			data.map((item,i)=>{
				if(v===item.name){
					dispatch({
						type: `${tag}/setState`,
						payload: {
							optimizeModel:item.value
						}
					})
				}
			})
		},
		placeholder:"请选择优化模型",
		style:{width:120},
	}
	return (
		<Row>
			<span>优化模型&nbsp;:&nbsp;</span>&nbsp;&nbsp;
			<Select {...myProps}>
				{
					 data.map((item,i)=><Option value={item.name} key={i}>{item.name}</Option>)
				}
			</Select>
		</Row>
	)
}

//优化规则
const OptimizationRules=({data,value,dispatch,tag})=>{
	const myProps={
		data,
		onChange:(v)=> {
			data.map((item,i)=>{
				if(v===item.name){
					dispatch({
						type: `${tag}/setState`,
						payload: {
							optimizeRules:item.value
						}
					})
				}
			})
		},
		placeholder:"请选择优化规则",
		style:{width:140},
	}
	return (
		<Row>
			<span>优化规则&nbsp;:&nbsp;</span>&nbsp;&nbsp;
			<Select {...myProps}>
				{
					 data.map((item,i)=><Option value={item.name} key={i}>{item.name}</Option>)
				}
			</Select>
		</Row>
	)
}

//预期目标收益：
const TargetIncome = ({value,dispatch,tag,OP})=>{
	const myProps={
		onChange:(v)=> {
			console.log('vvvv',v)
		},
		style:{width:80},
	}
	if(OP==0){
		return(
			<Row>
				<span>预期目标收益&nbsp;:&nbsp;</span>
				<InputNumber 
					{...myProps}
					formatter={value => `${value}%`}
	      	parser={value => value.replace('%', '')}
				/>
			</Row>
		)
	}else if(OP==1){
		return(
			<Row>
				<span>预期目标风险&nbsp;:&nbsp;</span>
				<InputNumber 
					{...myProps}
					formatter={value => `${value}%`}
	      	parser={value => value.replace('%', '')}
				/>
			</Row>
		)
	}else{
		return null;
	}
	
}

export {
	OptimizeModelSelect,
	OptimizationRules,
	TargetIncome
}